<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"> 
    
    <!--
    Author: Randall Chia
    -->
    
    <h:head>
        <title>View Cart</title>
        
        <link rel="stylesheet" type="text/css" href="CSS/RandallCSS.css" />
        
    </h:head>
    <h:body style="margin-left:150px; margin-right:150px;">
      
    
            
        
            <div class="Heading">
                <h:outputText value="#{fakeMainPortalMB.customerEmail}'s cart"/><br/>
            </div>
        
            <div class ="contentbox">
                    <h:form>
                            <br/>
                            <br/>
                            <p:dataTable value="#{cartBean.getItems()}" var="o"
                                 styleClass="order-table-shoppingcart"
                                 rowStyleClass="contentbox"
                                 emptyMessage="Your cart is empty"
                                 onRowEditUpdate="subtotal"
                                 rowEditListener="#{cartBean.updateListenAction}"
                                 >

                                <p:column style="width: 10px">
                                    <f:facet name="header">Item ID</f:facet>
                                    #{o.item_ID}
                                </p:column>

                                <p:column style="width: 50px">
                                    <f:facet name="header">Item Name</f:facet>
                                    #{o.item_name}
                                </p:column>

                                <p:column style="width: 10px">

                                    <f:facet name="header">Quantity</f:facet>
                                    <p:cellEditor>                        
                                        <f:facet name="output">  
                                            <h:outputText value="#{o.item_quantity}" />  
                                        </f:facet>

                                        <f:facet name="input">  
                                            <p:inputText id="quantityInput" value="#{o.item_quantity}">
                                                <f:validateLongRange minimum="1"/> 
                                            </p:inputText>              
                                            <p:message for="quantityInput"/>
                                        </f:facet>


                                    </p:cellEditor> 

                                    <p:rowEditor /> 
                                </p:column>

                                <p:column style="width: 30px">
                                    <f:facet name="header">Price</f:facet>
                                    <h:outputText value="#{o.item_price}" >
                                        <f:convertNumber type="currency" />
                                    </h:outputText>
                                </p:column>

                                <p:column style="width: 80px">
                                    <f:facet name="header">Seller</f:facet>
                                    #{o.seller}
                                </p:column>

                                <p:column style="width: 80px">
                                    <f:facet name="header">Outlet ID</f:facet>
                                    #{o.item_outletID}
                                </p:column>

                                <p:column style="width: 80px">
                                    <f:facet name="header">Outlet Name</f:facet>
                                    #{o.item_outletName}
                                </p:column>


                                <p:column style="width: 50px">                    
                                    <p:commandButton value="Remove" action="#{cartBean.removeFromCart(o)}" ajax="false"/>
                                </p:column>


                            </p:dataTable>

                    </h:form>   
            </div>
            <br/>
            <br/> 
            <h:form>
                Add in a preset list of items into the cart: <br/>
                <p:commandButton value="Add to cart demo" action="#{cartBean.addItems()}" ajax="false" update ="subtotal"/><br/>
                <br/>          
                Create transactionEntry and purchase items in the database with the current items in the cart. <br/>
                This simulates what is supposed to happen after payment validation.<br/>
                <p:commandButton value="transaction log  demo" action="#{cartBean.doTransactionLog()}" ajax="false" update ="subtotal"/><br/>
                <br/>
                Print out the cart on glassfish output<br/>
                <p:commandButton value="print cart" action="#{cartBean.printCart()}" ajax="false" update ="subtotal"/><br/>
                <br/>
                Remove all items in the cart<br/>
                <p:commandButton value="Empty Cart" onclick="dialogue_emptyCart.show();"/><br/>    
                
             <p:dialog header="Empty Cart" widgetVar="dialogue_emptyCart">  
                <h:outputText value="Are you sure you want to empty your cart?" /><br/>  
                <h:form>
                    <p:commandButton value="Yes" action="#{cartBean.emptyCart()}" oncomplete="dialogue_emptyCart.hide();" ajax="false" update ="subtotal"/>
                    <p:commandButton value="No"  oncomplete="dialogue_emptyCart.hide();" update ="subtotal"/>
                </h:form>
            </p:dialog>   
                <br/>
                <p:commandButton value="Go back" action="index.xhtml?faces-redirect=true"/> 
                
            </h:form>
            <br/>
            <br/>
            <br/>
            <b>Subtotal:</b>  <h:outputText id="subtotal" value="#{cartBean.getSubtotal()}" >
                                <f:convertNumber type="currency" />
                            </h:outputText>
            <br/>
            <br/>


            <form id="id_PaypalForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" 
                  style="margin-left:auto;margin-right:auto;">  
              
                 <input type="hidden" name="cmd" value="_xclick"/>  
                 <input type="hidden" name="business" value="zhou84_1317112812_biz@gmail.com"/>  
                 <input type="hidden" name="item_name"   value="Purchase Order"/>  
                 <input type="hidden" name="item_number" value="0"/>  
                 <input type="hidden" name="amount" value="#{cartBean.getSubtotal()}"/>  
                 <input type="hidden" name="tax" value="0"/>  
                 <input type="hidden" name="quantity" value="1"/>  
                 <input type="hidden" name="no_note" value="1"/>  
                 <input type="hidden" name="currency_code" value="SGD"/> 
                 <input type="hidden" name="return" value="http://localhost:8080/Foodsage-war/paymentcompleted.xhtml"/> 
                
                <input type="image" name="submit" border="0"
                        src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"  
                        alt="PayPal - The safer, easier way to pay online"
                />  
            </form>  




        
        
        
    </h:body>
</html>

